<template>
  <div class="edit-password">
    <el-form :model="form" :rules="rules" ref="form" label-width="100px">
      <el-form-item label="原密码" prop="old_password">
        <el-input v-model="form.old_password" size="medium" placeholder="请输入原密码" type="password"></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="new_password">
        <el-input v-model="form.new_password" size="medium" placeholder="请输入新密码" type="password"></el-input>
      </el-form-item>
      <el-form-item label="重复新密码" prop="new_password1">
        <el-input v-model="form.new_password1" size="medium" placeholder="请输入新密码" type="password"></el-input>
      </el-form-item>
    </el-form>
    <el-button type="primary" size="medium" @click="submit">确认修改</el-button>
  </div>
</template>

<script>
import { editPassword } from "./system.service.js";
export default {
  data() {
    return {
      form: {
        old_password: "",
        new_password: "",
        new_password1: ""
      },
      rules: {
        old_password: [
          { required: true, message: "原密码不能为空", trigger: "blur" }
        ],
        new_password: [
          { required: true, message: "新密码不能为空", trigger: "blur" }
        ],
        new_password1: [
          { required: true, message: "新密码不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          editPassword(this.form).then(res => {
            if (res.code == 0) {
              this.form = {
                old_password: "",
                new_password: "",
                new_password1: ""
              };
              this.$notify.success({
                title: "提示",
                message: "修改成功"
              });
            }
          });
        } else {
          this.$notify.warning({
            title: "提示",
            message: "密码信息不完整"
          });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.edit-password {
  padding-top: 30px;
  .el-input {
    width: 300px;
  }
  .el-button {
    margin: 30px 0 0 100px;
  }
}
</style>

